package mock

import java.io.{File, PrintWriter}
import com.google.gson.Gson
import scala.util.Random

object simulator {
  // 姓氏库
  val familyNames = Array(
    "李", "王", "张", "刘", "陈", "杨", "赵", "黄", "周", "吴",
    "苏", "唐", "闫", "谢", "韩", "梅", "卫", "蒋", "沈", "朱",
    "秦", "许", "何", "吕", "施", "孔", "曹", "严", "华", "金",
    "魏", "陶", "姜", "戚", "邹", "喻", "柏", "窦", "章", "云",
    "潘", "葛", "奚", "范", "彭", "鲁", "韦", "昌", "马", "苗"
  )

  // 名字库
  val givenNames = Array(
    "伟", "芳", "娜", "秀英", "敏", "静", "丽", "强", "磊", "洋",
    "道", "帅", "萍", "峰", "美美", "兰兰", "芳芳", "洁", "勇", "杰",
    "娟", "霞", "明", "超", "秀兰", "燕", "玲", "军", "浩", "宇",
    "鑫", "婷", "雪", "倩", "建国", "建军", "国庆", "建华", "国强", "志强",
    "淑珍", "淑兰", "桂英", "玉兰", "桂兰", "秀珍", "海燕", "红梅", "晓燕", "文静"
  )

  // 其他选项配置
  val genders = Array("男", "女")
  val targetPositions = Array(
    "测试工程师", "后端开发工程师", "前端开发工程师", "全栈开发工程师", "数据分析师",
    "数据工程师", "算法工程师", "移动开发工程师", "云计算工程师", "运维工程师"
  )
  val educationLevels = Array("专科", "本科", "硕士及以上")
  val universityTypes = Array("普通高校", "211高校", "985高校")
  val majorTypes = Array("计算机类", "非计算机类")
  val englishLevels = Array("英语四级", "英语六级", "无")
  val programmingLanguages = Array("Python", "Java", "JavaScript", "SQL", "Go")
  val expOptions = Array("1-3年", "3-5年", "5年以上")
  val screeningResults = Array("通过", "不通过")

  case class Resume(
                     resume_id: Int,
                     name: String,
                     gender: String,
                     age: Int,
                     phone: String,
                     target_position: String,
                     education_level: String,
                     university_type: String,
                     major_type: String,
                     english_level: String,
                     programming_languages: String,
                     small_business_experience: String,
                     middle_business_experience: String,
                     large_business_experience: String,
                     small_scale_project: Int,
                     middle_scale_project: Int,
                     large_scale_project: Int,
                     screening_result: String
                   )

  def generateResume(resumeId: Int): Resume = {
    val rand = new Random()

    Resume(
      resume_id = resumeId,
      name = familyNames(rand.nextInt(familyNames.length)) + givenNames(rand.nextInt(givenNames.length)),
      gender = genders(rand.nextInt(2)),
      age = 21 + rand.nextInt(20),
      phone = "1" + (1000000000L + rand.nextInt(900000000)).toString,
      target_position = targetPositions(rand.nextInt(targetPositions.length)),
      education_level = educationLevels(rand.nextInt(educationLevels.length)),
      university_type = universityTypes(rand.nextInt(universityTypes.length)),
      major_type = majorTypes(rand.nextInt(majorTypes.length)),
      english_level = englishLevels(rand.nextInt(englishLevels.length)),
      programming_languages = rand.shuffle(programmingLanguages.toList).take(1 + rand.nextInt(5)).mkString(","),
      small_business_experience = expOptions(rand.nextInt(3)),
      middle_business_experience = expOptions(rand.nextInt(3)),
      large_business_experience = expOptions(rand.nextInt(3)),
      small_scale_project = rand.nextInt(16),
      middle_scale_project = rand.nextInt(10),
      large_scale_project = rand.nextInt(3),
      screening_result = screeningResults(rand.nextInt(2))
    )
  }

  def main(args: Array[String]): Unit = {
    val printWriter = new PrintWriter(new File("output/resume_data.json"))
    val gson = new Gson()

    try {
      // 生成5000条简历数据 (0-4999)
      for (i <- 0 until 5000) {
        val resume = generateResume(i)
        val jsonString = gson.toJson(resume)

        println(s"生成第${i}条简历: $jsonString")
        printWriter.write(jsonString + "\n")
      }

      println("数据生成完成，已保存到 output/resume_data.json")
    } finally {
      printWriter.flush()
      printWriter.close()
    }
  }
}
